package game;

import javax.swing.JOptionPane;
import javax.swing.UIManager;

public class GraphicalMainMenu extends MainMenu {
	public GraphicalMainMenu(){

	}
	/**
	 * This method will setup the game and their view depending on the selection picked
	 */
	public void setUp(){
		view.View previousView = new view.ConsoleView(null);
		if(game != null){
			previousView = game.getView();
		}
		while(setGame(displayMenu()) != MainMenu.GAME_SET){}
		if(game != null){
			previousView.closeView();
		}
		if(game instanceof ChessGame){
			game.setView(new view.ChessGraphicalView((ChessGame)game));
		}else{
			game.setView(new view.GraphicalView(game.getBoard()));
		}
	}
	/**
	 * This method will display the menu at the start of the program as well as when a new game is
	 * about to be created. It will ask the user to pick a option from the list of games.
	 */
	public int displayMenu(){
		Object selection;
		String question = "Let's play a game !";
		UIManager.put("OptionPane.cancelButtonText", "Quit");  //Make it Quit for the Main Menu
		selection = JOptionPane.showInputDialog(null,question,"Main Menu",JOptionPane.QUESTION_MESSAGE,null,MainMenu.SELECTION_LIST,MainMenu.SELECTION_LIST[0]);
		UIManager.put("OptionPane.cancelButtonText", "Cancel");  //Revert it back to cancel in case you use another dialog.
		if(selection == null){
			return -1;
		}
		for(int i = 0; i < MainMenu.SELECTION_LIST.length;i++){
			if(selection.equals(MainMenu.SELECTION_LIST[i])){
				return i + 1;
			}
		}
		return -1;
	}
	
	/**
	 * Activate game now!!!!
	 * 
	 * <pre>
	 * Max Joyce 
	 * -Made the method, arbitrarily (Jan 22,2010)
	 * -Made method play a chess game, to test the game display (Jan 22,2010)
	 * </pre>
	 * 
	 */
	public static void main(String args[]){
		
		
		//Create the game
		MainMenu menu = new GraphicalMainMenu();
		menu.playGames();
	}
}
